﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TT.Logic.Entities;

namespace TT.Test
{
    [TestClass]
    public class MatchTest
    {     


        [TestMethod]
        public void ShouldNotHavePreviousMatches()
        {
            var match = new Match();
            for (int i = 0; i < 10; i++)
            {
                var previousMatches = match.GetPreviousMatches(1, i);
                Assert.IsNull(previousMatches);
            }
        }

        [TestMethod]
        public void ShouldReturnRound1Matches()
        {
            var match = new Match();            
            var previousMatches = match.GetPreviousMatches(2, 0);//1st Match, 2nd round
            Assert.AreEqual(0, previousMatches.Item1);
            Assert.AreEqual(1, previousMatches.Item2);

            previousMatches = match.GetPreviousMatches(2, 1);//2nd Match, 2nd round
            Assert.AreEqual(2, previousMatches.Item1);
            Assert.AreEqual(3, previousMatches.Item2);

            previousMatches = match.GetPreviousMatches(2, 2);//3rd Match, 2nd round
            Assert.AreEqual(4, previousMatches.Item1);
            Assert.AreEqual(5, previousMatches.Item2);

            previousMatches = match.GetPreviousMatches(2, 3);//4th Match, 2nd round
            Assert.AreEqual(6, previousMatches.Item1);
            Assert.AreEqual(7, previousMatches.Item2);

            previousMatches = match.GetPreviousMatches(2, 4);//5th Match, 2nd round
            Assert.AreEqual(8, previousMatches.Item1);
            Assert.AreEqual(9, previousMatches.Item2);
        }

        [TestMethod]
        public void ShouldReturnRound2Matches()
        {
            var match = new Match();
            var previousMatches = match.GetPreviousMatches(3, 0);//1st Match, 3rd round
            Assert.AreEqual(0, previousMatches.Item1);
            Assert.AreEqual(1, previousMatches.Item2);

            previousMatches = match.GetPreviousMatches(3, 1);//2nd Match, 3rd round
            Assert.AreEqual(2, previousMatches.Item1);
            Assert.AreEqual(3, previousMatches.Item2);

            previousMatches = match.GetPreviousMatches(3, 2);//3rd Match, 3rd round
            Assert.AreEqual(4, previousMatches.Item1);
            Assert.AreEqual(5, previousMatches.Item2);

            previousMatches = match.GetPreviousMatches(3, 3);//4th Match, 3rd round
            Assert.AreEqual(6, previousMatches.Item1);
            Assert.AreEqual(7, previousMatches.Item2);

            previousMatches = match.GetPreviousMatches(4, 4);//5th Match, 3rd round
            Assert.AreEqual(8, previousMatches.Item1);
            Assert.AreEqual(9, previousMatches.Item2);
        }


        [TestMethod]
        public void ShouldCheckIfFinished()
        {
            var match = new Match();
            match.AwayScore = 0;
            match.HomeScore = 0;
            Assert.IsFalse(match.IsFinished());

            match = new Match();
            match.AwayScore = 10;
            match.HomeScore = 10;
            Assert.IsFalse(match.IsFinished());

            match = new Match();
            match.AwayScore = 19;
            match.HomeScore = 19;
            Assert.IsFalse(match.IsFinished());

            match = new Match();
            match.AwayScore = 20;
            match.HomeScore = 20;
            Assert.IsFalse(match.IsFinished());

            match = new Match();
            match.AwayScore = 21;
            match.HomeScore = 21;
            Assert.IsFalse(match.IsFinished());

            match = new Match();
            match.AwayScore = 22;
            match.HomeScore = 22;
            Assert.IsFalse(match.IsFinished());

            match = new Match();
            match.AwayScore = 28;
            match.HomeScore = 28;
            Assert.IsFalse(match.IsFinished());

            match = new Match();
            match.AwayScore = 21;
            match.HomeScore = 10;//normal finish
            Assert.IsTrue(match.IsFinished());

            match = new Match();
            match.AwayScore = 21;
            match.HomeScore = 19;//normal finish
            Assert.IsTrue(match.IsFinished());

            match = new Match();
            match.AwayScore = 21;
            match.HomeScore = 20;
            Assert.IsFalse(match.IsFinished());

            match = new Match();
            match.AwayScore = 22;
            match.HomeScore = 20;//2 points diff
            Assert.IsTrue(match.IsFinished());

            match = new Match();
            match.AwayScore = 23;
            match.HomeScore = 21;//2 points diff
            Assert.IsTrue(match.IsFinished());

            match = new Match();
            match.AwayScore = 23;
            match.HomeScore = 22;
            Assert.IsFalse(match.IsFinished());

            match = new Match();
            match.AwayScore = 20;
            match.HomeScore = 0;
            Assert.IsFalse(match.IsFinished());
        }

  

    }
}
